home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / error.test < prev    next >
Text File  |  1993-02-06  |  6KB  |  186 lines

  1. # Commands covered:  error, catch
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/error.test,v 1.12 93/02/06 15:54:01 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. proc foo {} {
  32.     global errorInfo
  33.     set a [catch {format [error glorp2]} b]
  34.     error {Human-generated}
  35. }
  36.  
  37. proc foo2 {} {
  38.     global errorInfo
  39.     set a [catch {format [error glorp2]} b]
  40.     error {Human-generated} $errorInfo
  41. }
  42.  
  43. # Catch errors occurring in commands and errors from "error" command
  44.  
  45. test error-1.1 {simple errors from commands} {
  46.     catch {format [string compare]} b
  47. } 1
  48.  
  49. test error-1.2 {simple errors from commands} {
  50.     catch {format [string compare]} b
  51.     set b
  52. } {wrong # args: should be "string compare string1 string2"}
  53.  
  54. test error-1.3 {simple errors from commands} {
  55.     catch {format [string compare]} b
  56.     set errorInfo
  57. } {wrong # args: should be "string compare string1 string2"
  58.     while executing
  59. "string compare"
  60.     invoked from within
  61. "format [string compare]..."}
  62.  
  63. test error-1.4 {simple errors from commands} {
  64.     catch {error glorp} b
  65. } 1
  66.  
  67. test error-1.5 {simple errors from commands} {
  68.     catch {error glorp} b
  69.     set b
  70. } glorp
  71.  
  72. test error-1.6 {simple errors from commands} {
  73.     catch {catch a b c} b
  74. } 1
  75.  
  76. test error-1.7 {simple errors from commands} {
  77.     catch {catch a b c} b
  78.     set b
  79. } {wrong # args: should be "catch command ?varName?"}
  80.  
  81. test error-2.1 {simple errors from commands} {
  82.     catch catch
  83. } 1
  84.  
  85. # Check errors nested in procedures.  Also check the optional argument
  86. # to "error" to generate a new error trace.
  87.  
  88. test error-2.1 {errors in nested procedures} {
  89.     catch foo b
  90. } 1
  91.  
  92. test error-2.2 {errors in nested procedures} {
  93.     catch foo b
  94.     set b
  95. } {Human-generated}
  96.  
  97. test error-2.3 {errors in nested procedures} {
  98.     catch foo b
  99.     set errorInfo
  100. } {Human-generated
  101.     while executing
  102. "error {Human-generated}"
  103.     (procedure "foo" line 4)
  104.     invoked from within
  105. "foo"}
  106.  
  107. test error-2.4 {errors in nested procedures} {
  108.     catch foo2 b
  109. } 1
  110.  
  111. test error-2.5 {errors in nested procedures} {
  112.     catch foo2 b
  113.     set b
  114. } {Human-generated}
  115.  
  116. test error-2.6 {errors in nested procedures} {
  117.     catch foo2 b
  118.     set errorInfo
  119. } {glorp2
  120.     while executing
  121. "error glorp2"
  122.     invoked from within
  123. "format [error glorp2]..."
  124.     (procedure "foo2" line 1)
  125.     invoked from within
  126. "foo2"}
  127.  
  128. # Error conditions related to "catch".
  129.  
  130. test error-3.1 {errors in catch command} {
  131.     list [catch {catch} msg] $msg
  132. } {1 {wrong # args: should be "catch command ?varName?"}}
  133. test error-3.2 {errors in catch command} {
  134.     list [catch {catch a b c} msg] $msg
  135. } {1 {wrong # args: should be "catch command ?varName?"}}
  136. test error-3.3 {errors in catch command} {
  137.     catch {unset a}
  138.     set a(0) 22
  139.     list [catch {catch {format 44} a} msg] $msg
  140. } {1 {couldn't save command result in variable}}
  141. catch {unset a}
  142.  
  143. # More tests related to errorInfo and errorCode
  144.  
  145. test error-4.1 {errorInfo and errorCode variables} {
  146.     list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
  147. } {1 msg1 msg2 msg3}
  148. test error-4.2 {errorInfo and errorCode variables} {
  149.     list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
  150. } {1 msg1 {msg1
  151.     while executing
  152. "error msg1 {} msg3"} msg3}
  153. test error-4.3 {errorInfo and errorCode variables} {
  154.     list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
  155. } {1 msg1 {msg1
  156.     while executing
  157. "error msg1 {}"} NONE}
  158. test error-4.4 {errorInfo and errorCode variables} {
  159.     set errorCode bogus
  160.     list [catch {error msg1} msg] $msg $errorInfo $errorCode
  161. } {1 msg1 {msg1
  162.     while executing
  163. "error msg1"} NONE}
  164. test error-4.5 {errorInfo and errorCode variables} {
  165.     set errorCode bogus
  166.     list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
  167. } {1 msg1 msg2 {}}
  168.  
  169. # Errors in error command itself
  170.  
  171. test error-5.1 {errors in error command} {
  172.     list [catch {error} msg] $msg
  173. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  174. test error-5.2 {errors in error command} {
  175.     list [catch {error a b c d} msg] $msg
  176. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  177.  
  178. # Make sure that catch resets error information
  179.  
  180. test error-6.1 {catch must reset error state} {
  181.     catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
  182.     list $errorCode $errorInfo
  183. } {NONE 1}
  184.  
  185. return ""
  186.